package initialize

import (
	"fmt"
	"github.com/go-redis/redis"
	"github.com/liangchao/blogo/src/common/global"
	"log"
)

// InitRedis 初始化 redis
func InitRedis() {
	addr := fmt.Sprintf("%s:%d", global.Settings.RedisInfo.Host, global.Settings.RedisInfo.Port)

	global.Redis = redis.NewClient(&redis.Options{
		Addr:     addr,
		Password: global.Settings.RedisInfo.Password,
		DB:       0,
	})

	_, err := global.Redis.Ping().Result()
	if err != nil {
		log.Println(err)
	}
}
